package com.itheima.demo.ZuoYe;

import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

//分析需求,代码实现
//	1.统计每个单词出现的次数
//	2.有如下字符串"If you want to change your fate
// I think you must come to the dark horse to learn java"(用空格间隔)
//	3.打印格式：
//	    to=3
//	    think=1
//	    you=2
public class JIshu {
    public static void main(String[] args) throws IOException {
        String s = "If you want to change your fate I think you must come to the dark horse to learn java";
        String[] ss = s.split(" ");
        Map<String, Integer> map = new HashMap<>();
        for (String s1 : ss) {
            if(map.containsKey(s1)){
                Integer value = map.get(s1);
                value++;
                map.put(s1,value);
            }else {
                map.put(s1,1);
            }

        }
        Set<Map.Entry<String, Integer>> entries = map.entrySet();
        for (Map.Entry<String, Integer> entry : entries) {
            Integer value = entry.getValue();
            String key = entry.getKey();
            System.out.println(key+"="+value);



        }

     /*   for (int i = 0; i < ss.length; i++) {
            if(map.containsKey(ss[i])){
                int integer = map.get(ss[i]);
                integer++;
                map.put(ss[i],integer);
            }else {
                map.put(ss[i],1);
            }
        }
        Set<Map.Entry<String, Integer>> entries = map.entrySet();
        for (Map.Entry<String, Integer> entry : entries) {
            System.out.println(entry.getKey()+"="+entry.getValue());
        }*/
        /*for (String s1 : ss) {
            if (map.containsKey("to")) {
                Integer value1 = map.get("to");
                value1++;
                map.put("to", value1);
            }
            if (map.containsKey("think")) {
                Integer value2 = map.get("think");
                value2++;
                map.put("think", value2);

            }
            if (map.containsKey("you")) {
                Integer value3 = map.get("you");
                value3++;
                map.put("you", value3);


            }
        }
        for (String key : map.keySet()) {
            Integer value = map.get(key);
            System.out.println(key+" "+value);



        }

    }*/
    }
}